package com.example.mymvvmdemo.models.add_device.adapter;

import android.content.Context;
import android.view.View;

import com.example.mymvvmdemo.R;
import com.example.mymvvmdemo.base.BaseVBAdapter;
import com.example.mymvvmdemo.databinding.ItemDeviceTypeBinding;
import com.example.mymvvmdemo.models.add_device.entity.DeviceTypeListEntity;
import com.example.mymvvmdemo.utils.StrUtils;

import java.util.ArrayList;

public class DeviceTypeAdapter extends BaseVBAdapter<DeviceTypeListEntity.DataDTO.DeviceTypesDTO, ItemDeviceTypeBinding> {

    public DeviceTypeListener listener;

    public void setListener(DeviceTypeListener listener) {
        this.listener = listener;
    }

    /**
     * @param context
     */
    public DeviceTypeAdapter(Context context, ArrayList<DeviceTypeListEntity.DataDTO.DeviceTypesDTO> list) {
        super(context);
        setDataList(list);
    }

    @Override
    protected void updateData(ItemDeviceTypeBinding bind, DeviceTypeListEntity.DataDTO.DeviceTypesDTO item, int position) {

        if (item == null) {
            return;
        }

        if (position == getDataListSize() - 1) {
            bind.viewLine.setVisibility(View.GONE);
        }

        String name = item.getName();
        if (!StrUtils.isEmpty(name)) {
            bind.tvType.setText(name);
        }

        boolean select = item.isSelect();
        bind.tvType.setTextColor(select ? context.getColor(R.color.green_one) : context.getColor(R.color.black_two));

        bind.clAll.setOnClickListener(view -> {
            if (listener != null) {
                listener.onClickTypeListener(position);
            }
        });

    }

    public interface DeviceTypeListener {
        void onClickTypeListener(int position);
    }

}
